

import {downloadFile,filedownload,UploadFile} from "@/api/system";
const basisfile = {
  data() {
    return {
      basisFileListMixin:[],
    }
  },
  methods:{
    // 立项依据附件上传
    basisSubmitUploadMixin(param) {
      const formData = new FormData()
      formData.append(param.file.uid, param.file)
      UploadFile(formData,{fileType:'1'}, param).then(response => {
        if (response.data.code == 0) {
          this.projectForm.basisFileId = response.data.data;
          this.basisFileListMixin = [{name: param.file.name, url: response.data.data}];
          console.log(this.basisFileListMixin,this.projectForm.basisFileId)
          this.$notify({
            title: "成功",
            message: "上传成功1111111",
            type: "success",
            duration: 2000
          });
        }
      }).catch(response => {
        this.basisFileListMixin = [];
        this.$notify({
          title: "失败",
          message: "上传失败",
          type: "error",
          duration: 2000
        });

      })
    },
    //立项依据附件修改
    basisFileChangeMixin(file){
      console.log(file)
    },
    //立项依据附件删除
    basishandleRemoveMixin(file, fileList) {
      this.projectForm.basisFileId = null;
      this.basisFileListMixin = fileList;
    },
    // 点击文件列表中已上传的文件时
    basishandlePreviewMixin(file) {
      filedownload(file.url).then(response => {
        if(response.status==200){
          this.downloadMixin(response.data,file.name)
        }
      }).catch((error) => {

      })
    },
    // 下载文件
    downloadMixin (data,filename) {
      if (data==null) {
        return
      }else{
        let url = window.URL.createObjectURL(new Blob([data]))
        let link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        link.setAttribute('download',filename )
        document.body.appendChild(link)
        link.click()
      }
    },
  }


};

export default basisfile;
